package top.kiterunner.trial.tbgp;

import java.io.*;

/**
 * AdorynZhao in Tencent-UESTC.
 * Source Code Created on 2017/7/13.
 */
public class Main {

    public static void main(String[] args) {
        // 读时延矩阵文件
        int[][] matrix = new int[10][10];

        InputStream is1 =  ClassLoader.getSystemResourceAsStream("matrix_demo.txt");
        BufferedReader br1 = null;

        try {
            System.out.println("Read Matrix File.");
            br1 = new BufferedReader(new InputStreamReader(is1));
            String tmp;

            while ((tmp = br1.readLine()) != null) {
                System.out.println("Line Content = " + tmp);
                if (tmp.length() != 0) {
                    String[] strs = tmp.split("\t");

                if (strs != null && strs.length != 0) {
                    int delay = Integer.parseInt(strs[0]);

                    System.out.println("Delay[delay + 2222] = " + (delay + 2222));

                    System.out.println("Delay[strdelay + 2222] = " + (strs[0] + 2222));

                    for (String s : strs) {
                        System.out.println(s);
                    }
                }
                }
            }
            br1.close();
            is1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 读前缀表
        RouteTable table = new RouteTable();
        //......

        InputStream is2 =  ClassLoader.getSystemResourceAsStream("prefix_demo.txt");
        BufferedReader br2 = null;

        try {
            System.out.println("Read Prefix File.");
            br2 = new BufferedReader(new InputStreamReader(is2));
            String tmp;

            while ((tmp = br2.readLine()) != null) {
                System.out.println("Line Content = " + tmp);
            }
            br2.close();
            is2.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 跑算法
        Algorithm algorithm = new Algorithm(matrix, table);

        RouteTable result = algorithm.run();

        // 打印最后的前缀路由表
        // print .....
        System.out.println(result);
    }
}
